#字典

#1 key不可重复，key是任意不可变的类型，所以list不可以作为key
# person = {"name":'fangyukui',"age":16,"gender":'female'}
# print(person)

#2  字典静态方法
# result = dict.fromkeys('abc',666)
# print(result)

# result = dict.fromkeys([1,2,3],666)
# print(result)


#删除1 del 删除的key必须存在，不然报错
# person = {'name':'fangyukui','age':18}
# del person['name']
# print(person)

#删除2  del可以删除整个字典，删除后person为not defined
# person = {'name':'fangyukui','age':18}
# del person
# print(person)


#删除3  clear清空整个字典，清空后person为{}空字典
# person = {'name':'fangyukui','age':18}
# person.clear()
# print(person)

#删除4  pop
# person = {'name':'fangyukui','age':18}
# result = person.pop('name')
# print(result,person)

# result = person.pop('name1','找不到的默认返回值，不设置会报错')
# print(result,person)




# 删除5 popitem 对字典增序，移除并返回第一个元祖
# person = {'name':'fangyukui','age':18}
# result = person.popitem()
# print(result,person)


# 修改1
# person = {'name':'fangyukui','age':18}
# person['name'] =  'yu-vin'
# print(person)

# 修改2 批量修改
# person = {'name':'fangyukui','age':18}
# person.update({'name':'yu-vin','age':20,'gender':'female'})
# print(person)


# 查找
# person['name'],找不到key直接报错
# person = {'name':'fangyukui','age':18}
# print(person['name'])

# get(),找不到直接返回none，可以指定默认值
# print(person.get('name','找不到返回值'))

# 获取所有 获取的类型是 Dictionaty view objects字典视图模型
# person = {'name':'fangyukui','age':18,'gender':'female'}
# print(person.keys())
# print(person.values())
# print(person.items())
# print(tuple(person.items())) #元祖
# print(list(person.items()))  #列表














